home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Softshoe / Lisa's Mac Parts / MouseWatcher / MouseWatcher.cp next >
Text File  |  2000-06-23  |  1KB  |  73 lines

  1. // MouseWatcher.cp
  2.  
  3. #ifndef MouseWatcher_h
  4. #include "MouseWatcher.h"
  5. #endif
  6. #ifndef ListLoop_h
  7. #include "ListLoop.h"
  8. #endif
  9. #ifndef ListOf_h
  10. #include "ListOf.h"
  11. #endif
  12. #ifndef MouseEvent_h
  13. #include "MouseEvent.h"
  14. #endif
  15.  
  16. MouseWatcher::MouseWatcher( bool startEnabled )
  17.   : Enableable( startEnabled ),
  18.      link( this )
  19.   {
  20.     if ( startEnabled )
  21.         BeEnabled();
  22.   }
  23.  
  24. ListOf< MouseWatcher >& MouseWatcher::TheList()
  25.   {
  26.     static ListOf<MouseWatcher> theList;
  27.     return theList;
  28.   }
  29.  
  30. void MouseWatcher::BeEnabled()
  31.   {
  32.     TheList().Add( link, afterEnd );
  33.   }
  34.  
  35. void MouseWatcher::BeDisabled()
  36.   {
  37.     TheList().Remove( link );
  38.   }
  39.  
  40. const RegionObject& MouseWatcher::MouseSleepRegion()
  41.   {
  42.     static RegionObject region( Rectangle::big );
  43.     
  44.     region = Rectangle::big;
  45.     
  46.     for ( ListLoop<MouseWatcher> watcher( TheList() );
  47.             watcher.Unfinished();
  48.             watcher++ )
  49.         region &= watcher->sleepRegion;
  50.     
  51.     return region;
  52.   }
  53.  
  54. void MouseWatcher::Report( const MouseEvent& event )
  55.   {
  56.     for ( ListLoop<MouseWatcher> watcher( TheList() );
  57.             watcher.Unfinished();
  58.             watcher++ )
  59.       {
  60.         if ( watcher->sleepRegion.Contains( event.GlobalPoint() ) )
  61.             continue;
  62.         
  63.         watcher->sleepRegion = Rectangle( event.GlobalPoint().h,
  64.                                                      event.GlobalPoint().v,
  65.                                                      event.GlobalPoint().h + 1,
  66.                                                      event.GlobalPoint().v + 1 );
  67.         
  68.         watcher->MouseMoved( event, watcher->sleepRegion );
  69.         
  70.         Assert( watcher->sleepRegion.Contains( event.GlobalPoint() ) );
  71.       }
  72.   }
  73.